<?php
/*
 * 获取九华天气信息
 */
class WeathersController extends CController{
	public function actionList(){
		$key = '0d291452bc581a021494f7b4bdbb3d5d';
		$apptk = isset($_GET['apptk']) ? $_GET['apptk']:'';
		if ($apptk !='' && $key == $apptk){
			$url = 'http://m.weather.com.cn/data/101221701.html';
			$json = file_get_contents($url);
			$json = json_decode($json);
			if(!empty($json)){
				$array = array();
				$array['isok'] = true;
				foreach ($json as $value){
					$arr =array();
					$string = (String)$value->temp1;
					$arrstring = explode('~',$string);
					$arr['Height'] = $arrstring[0];
					$arr['Low'] = $arrstring[1];
					$arr['Temperature'] = (String)$value->st1;
					$arr['Text'] = (String)$value->weather1;
					$array['data'][] = $arr;
				}
				echo json_encode($array);
			}else {
				$err = array(
					'isok'=>false,
					'msg' =>'数据为空！',
				);
				echo json_encode($err);
			}
		}else {
			$error = array(
					'isok'=>false,
					'msg' =>'秘钥有误！',
			);
			echo json_encode($error);
			
		}
	}
}
?>